import api from '../../http/api'

export default {
    namespaced: true,
    state: {
        appointmentData:[],
        appointmentData1:[],
        appointmentData2:[],
        currentPage: 1,
        pageSize: 4,
        pages: 0,
        total: 0,
        pages1: 0,
        total1: 0,
        pages2: 0,
        total2: 0,
        
    },
    mutations: {
        GetAppointmentData(state,data){
            state.appointmentData = data.data,
            state.pages = data.pages,
            state.total = data.total
            // console.log('data', data);
        },
        GetAppointmentData1(state,data){
            state.appointmentData1 = data.data,
            state.pages1 = data.pages,
            state.total1 = data.total
            // console.log('data1', data);
        },
        GetAppointmentData2(state,data){
            state.appointmentData2 = data.data,
            state.pages2 = data.pages,
            state.total2 = data.total
            // console.log('data2', data);
        },
        setCurrentPage(state, data) {
            state.currentPage = data
        },
        setPageSize(state, data) {
            state.pageSize = data
        }
    },
    actions: {
        async GetAppointment(context,state) {
            let res=  await api.appointment.GetAppointment({
                
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                data:{
                    reservationState:state
                }
            })
            if(res.data.code==200){
                context.commit('GetAppointmentData',res.data.data)
            }
        },
        async GetAppointment1(context,state) {
            let res=  await api.appointment.GetAppointment({
                
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                data:{
                    reservationState:1
                }
            })
            if(res.data.code==200){
                context.commit('GetAppointmentData1',res.data.data)
            }
        },
        async GetAppointment2(context,state) {
            let res=  await api.appointment.GetAppointment({
                
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                data:{
                    reservationState:2
                }
            })
            if(res.data.code==200){
                context.commit('GetAppointmentData2',res.data.data)
            }
        },
        async DelAppointment(context, id) {
            return api.appointment.DelAppointment(id);
        },
      async  UpdateAppointment(context, data) {
            return  api.appointment.UpdateAppointment(data);
        }
    },
}